import { $get } from '@js/request'
import { CaseSchema } from '@src/components/schema/caseSchema'
import { ConditionSchema } from '@src/components/schema/condition'

export async function getCaseListRequest (d: { condition: ConditionSchema[], page: number, limit: number }): Promise<{ list: CaseSchema[], total: number }> {
  const tkey: string[] = ['begin_datetime']
  const condition = d.condition.map(li => {
    if (tkey.includes(li.k)) {
      li.k = `t.${li.k}`
    } else {
      li.k = `c.${li.k}`
    }
    return li
  })
  const res = await $get('/api/commission/casestat/hearing', {
    condition: JSON.stringify(condition),
    page: d.page,
    limit: d.limit
  })
  const list: CaseSchema[] = res.data.list
  list.forEach((li, i) => {
    li.orderno = (d.page - 1) * d.limit + i + 1
  })
  return res.data
}
